import 'package:flutter/material.dart';
import 'package:hc_ui/config/hc_customer_config.dart';

import 'package:hc_ui/initialize/hc_initialize.dart';
import 'package:hc_ui/theme/hc_all_theme.dart';
import 'package:hc_ui/theme/hc_cell_group_theme.dart';

import 'package:hc_ui/widget/cell/hc_cell.dart';
import 'package:hc_ui/widget/cell_group/hc_cell_group.dart';

import 'package:hc_ui/widget/title/hc_full_title.dart';
import 'package:hc_ui/widget/title/hc_title.dart';
import 'package:hc_ui_example/feedback/hc_button_page.dart';
import 'package:hc_ui_example/feedback/hc_dialog_page.dart';
import 'package:hc_ui_example/feedback/hc_steps_page.dart';
import 'package:hc_ui_example/feedback/hc_toast_page.dart';

import 'package:hc_ui_example/from/hc_switch_page.dart';
import 'package:hc_ui_example/layout/hc_cell_group_page.dart';
import 'package:hc_ui_example/layout/hc_grid_page.dart';
import 'package:hc_ui_example/layout/hc_icon_text_page.dart';
import 'package:hc_ui_example/view/hc_avatar_page.dart';
import 'package:hc_ui_example/view/hc_divider_page.dart';
import 'package:hc_ui_example/view/hc_ellipsis_page.dart';
import 'package:hc_ui_example/view/hc_image_page.dart';
import 'package:hc_ui_example/view/hc_marquee_page.dart';
import 'package:hc_ui_example/view/hc_progress_page.dart';
import 'package:hc_ui_example/view/hc_tag_page.dart';
import 'package:hc_ui_example/view/hc_title_page.dart';

import 'view/hc_notice_bar_page.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    HcUiInitialize.register(themeData: HcAllTheme());
    // initPlatformState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  final List<Map<String, dynamic>> viewList = [
    {
      "name": '头像',
      "icon": const Icon(Icons.account_circle_outlined),
      "page": const HcAvatarPage()
    },
    {
      "name": '标题',
      "icon": const Icon(Icons.text_fields_outlined),
      "page": const HcTitlePage()
    },
    {
      "name": '图片',
      "icon": const Icon(Icons.wallpaper_rounded),
      "page": const HcImagePage()
    },
    {
      "name": '进度条',
      "icon": const Icon(Icons.donut_large_outlined),
      "page": const HcProgressPage()
    },
    {
      "name": '分割线',
      "icon": const Icon(Icons.more_horiz_outlined),
      "page": const HcDividerPage()
    },
    {
      "name": '跑马灯',
      "icon": const Icon(Icons.clear_all_outlined),
      "page": const HcMarqueePage()
    },
    {
      "name": '通知条',
      "icon": const Icon(Icons.campaign_outlined),
      "page": const HcNoticeBarPage()
    },
    {
      "name": '缩略文字',
      "icon": const Icon(Icons.menu_open_outlined),
      "page": const HcEllipsisPage()
    },    {
      "name": '标签',
      "icon": const Icon(Icons.bookmark),
      "page": const HcTagPage()
    },
  ];
  final List<Map<String, dynamic>> feedBackList = [
    {
      "name": '步骤条',
      "icon": const Icon(Icons.commit_outlined),
      "page": const HcStepsPage()
    },
    {
      "name": '按钮',
      "icon": const Icon(Icons.smart_button_outlined),
      "page": const HcButtonPage()
    },
    {
      "name": '吐司',
      "icon": const Icon(Icons.tips_and_updates_outlined),
      "page": const HcToastPage(),
    },
    {
      "name": '弹窗',
      "icon": const Icon(Icons.add_alert),
      "page": const HcDialogPage()
    }
  ];
  final List<Map<String, dynamic>> layoutList = [
    {
      "name": '宫格',
      "icon": const Icon(Icons.grid_view_outlined),
      "page": const HcGridPage()
    },
    {
      "name": '单元格组',
      "icon": const Icon(Icons.table_rows),
      "page": const HcCellGroupPage()
    },
    {
      "name": '图片-文字',
      "icon": const Icon(Icons.vertical_split_outlined),
      "page": const HcIconTextPage()
    }
  ];
  final List<Map<String, dynamic>> fromList = [
    {
      "name": 'switch 开关',
      "icon": const Icon(Icons.toggle_on_outlined),
      "page": const HcSwitchPage()
    }
  ];

  HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: HcCustomerConfig().allTheme.commonTheme.fillPageColor,
      appBar: AppBar(
        title: const Text("Hc UI Demo"),
      ),
      body: ListView(
          padding: EdgeInsets.symmetric(
              vertical: HcCustomerConfig().allTheme.commonTheme.vSpacingPage,
              horizontal: HcCustomerConfig().allTheme.commonTheme.vSpacingPage),
          children: [
            const HcFullTitle(
              title: "Flutter UI 组件库",
              subtitle: 'hc ui demo',
              subTitleCapitalize: true,
            ),
            HcTitle.dot(
              title: '视图',
            ),
            HcCellGroup(
                showArrow: true,
                themeData: HcCellGroupTheme(leftIndent: 8, rightIndent: 8),
                onTap: (type, index, title) {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => viewList[index]['page']));
                },
                children: viewList
                    .map((e) => HcCell(
                          title: e['name'],
                          leading: e['icon'],
                        ))
                    .toList()),
            const HcTitle.dot(
              title: '交互',
            ),
            HcCellGroup(
                showArrow: true,
                themeData: HcCellGroupTheme(leftIndent: 16, rightIndent: 0),
                onTap: (type, index, title) {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => feedBackList[index]['page']));
                },
                children: feedBackList
                    .map((e) => HcCell(
                          title: e['name'],
                          leading: e['icon'],
                          subtitle: "这是副标题",
                        ))
                    .toList()),
            const HcTitle.dot(
              title: '布局',
            ),
            HcCellGroup(
                showArrow: true,
                onTap: (type, index, title) {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => layoutList[index]['page']));
                },
                children: layoutList
                    .map((e) => HcCell(
                          title: e['name'],
                          leading: e['icon'],
                        ))
                    .toList()),
            const HcTitle.dot(
              title: '表单',
            ),
            HcCellGroup(
                showArrow: true,
                onTap: (type, index, title) {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => fromList[index]['page']));
                },
                children: fromList
                    .map((e) => HcCell(
                          title: e['name'],
                          leading: e['icon'],
                        ))
                    .toList()),
          ]), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
